<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>新增人员</title>
<link rel="stylesheet" type="text/css" href="${path}/static/plugins/layui/css/layui.css"/>
</head>

<body>

<fieldset class="layui-elem-field layui-field-title">
    <legend>新增人员</legend>
</fieldset>

<form class="layui-form" id="form" action="/app/user/add/user" method="post">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">电话号码</label>
            <div class="layui-input-inline">
                <input type="text" name="phone" lay-verify="phone" autocomplete="off" class="layui-input" maxlength="11" minlength="11"/>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
                <input type="text" name="password" lay-verify="password" value="abcd1234" autocomplete="off" class="layui-input"/>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="sub">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary" onclick="history.back();">返回</button>
        </div>
    </div>
</form>

<!-- 全局js -->
<script src="${path}/static/Hui/js/jquery.min.js?v=2.1.4"></script>
<script src="${path}/static/Hui/js/bootstrap.min.js?v=3.3.6"></script>
<script src="${path}/static/plugins/layui/layui.js"></script>
<script type="text/javascript" src="${path}/static/plugins/validator.min.js" ></script>

<!-- 自定义js -->
<script src="${path}/static/Hui/js/content.js?v=1.0.0"></script>
<script>
    $(function(){
        // 模块加载
        layui.use(['form'], function() {

            var form = layui.form;

            //自定义验证规则
            form.verify({
                phone: function(value) {
                    if (value.length != 11) {
                        return '电话号码长度为11位';
                    }
                }
            });

            //监听提交
            form.on('submit(sub)', function(data){
                var action = $("#form").attr("action");
                $.ajax({
                    type:"post",
                    url:action,
                    dataType:"json",
                    data:$('#form').serialize(),
                    success:function(data){
                        if(data.code >= 0){
                            layer.alert(data.msg,{icon:1}, function(){
                                window.location.href = "/app/user/index"
                            });
                        }else{
                            layer.alert(data.msg,{icon:2});
                        }
                    }
                });
                return false;
            });
        });
    });
</script>
</body>
</html>